<template>
  <div class="bigBox">
    <div class="left">
      <el-scrollbar
        class="messageContent"
        style="box-sizing: border-box; padding-right: 30px"
        max-height="600px"
      >
        <div
          v-for="(item, index) in messageList"
          :class="item.role === 'assistant' ? 'aiMessage' : 'myMessage'"
        >
          <div v-if="isLoading && index === messageList.length - 1" class="message">
            <img
              style="
                padding: 0 10px;
                width: 20px;
                height: 20px;
                transform: scale(3) translateY(2px);
              "
              src="../../assets/loading.gif"
              alt=""
            />
          </div>
          <div v-else class="message" v-html="md.render(item.content)"></div>
        </div>
      </el-scrollbar>
      <div class="inputBox">
        <input
          class="input"
          name="text"
          type="text"
          v-model="input"
          placeholder="请输入你的问题..."
        />
        <button @click="sendMessage">提问</button>
      </div>
    </div>
    <div class="right">
      <div class="notice">注意！该助手仅提供咨询，如果您遇到困难，建议寻找专业律师帮忙！</div>
      <img src="../../assets/image/layer.png" alt="" />
    </div>
  </div>
</template>

<script lang="ts" setup>
import type { MessageList } from '@/types/home'
import { ref } from 'vue'
import MarkdownIt from 'markdown-it'
let md: MarkdownIt = new MarkdownIt()

const input = ref('请问如何学习')
const isLoading = ref(false)

const sendMessage = () => {}

const messageList = ref<MessageList>([
  {
    role: 'user',
    content: '你好',
  },
  {
    role: 'assistant',
    content: '你好我是你的ai小助手',
  },
])
</script>

<style lang="scss" scoped>
.bigBox {
  // background-color: red;
  display: flex;

  .left {
    flex: 1;
    margin-right: 20px;
    height: calc(100vh - 200px);
    display: flex;
    flex-direction: column;

    .messageContent {
      padding: 20px 80px;
      flex: 1;
    }

    .aiMessage {
      display: flex;
      justify-content: left;
      margin-bottom: 20px;
      margin-right: 20px;

      .avatar {
        margin-right: 20px;
      }

      .message {
        // flex: 1;
        background: rgba(255, 255, 255, 1);
        // border: 1px solid $primary-border-color;
        background-color: $primary-message-background-color;
        box-sizing: border-box;
        padding: 20px;
        border-radius: 20px 20px 20px 0px;
        //   border:1px solid $primary-border-color;
      }
    }

    .myMessage {
      margin-bottom: 20px;
      margin-right: 20px;
      display: flex;
      justify-content: right;

      .message {
        background-color: $primary-color;
        box-sizing: border-box;
        padding: 20px;
        color: white;
        margin-left: 70px;
        border-radius: 20px 20px 0 20px;
      }
    }

    .inputBox {
      display: flex;
      margin-left: 70px;
      margin-right: 60px;

      button {
        width: 200px;
        font-size: 18px;
        border-radius: 30px;
        border: none;
        color: white;
        opacity: 1;
        margin-left: 20px;
        background: linear-gradient(142.41deg, rgba(74, 37, 225, 1) 0%, rgba(53, 120, 246, 1) 100%);
        box-shadow: 0px 21px 27px -10px rgba(96, 60, 255, 0.48);
        display: flex;
        justify-content: center;
        align-items: center;
      }

      .input {
        width: 100%;
        //   max-width: 220px;
        height: 30px;
        padding: 12px;
        border-radius: 20px;
        border: 1.5px solid lightgrey;
        outline: none;
        transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
        box-shadow: 0px 0px 20px -18px;
      }

      .input:hover {
        border: 2px solid lightgrey;
        box-shadow: 0px 0px 20px -17px;
      }

      .input:active {
        transform: scale(0.95);
      }

      .input:focus {
        border: 2px solid grey;
      }
    }
  }

  .right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-top: 20px;

    .notice {
      width: 300px;
      flex: 1;
      box-sizing: border-box;
      padding: 20px;
      box-shadow:
        rgba(17, 17, 26, 0.1) 0px 4px 16px,
        rgba(17, 17, 26, 0.05) 0px 8px 32px;

      border-radius: 20px;
    }

    img {
      width: 300px;
    }
  }
}
</style>
